import React from 'react'
// ===================================================================== Cols
import Table from '#cpt/temp/Table'
import TableControls from '#cpt/temp/TableControls'
import Controls from '#cpt/temp/Controls'
import { Status, CardType, CaseType, Sex, MultipleType, CheckType } from '../../common/defaultData'
// ===================================================================== global declare
const { $fn, $Lazy, globalConfig } = window
const { COVIDUrl } = globalConfig
// ===================================================================== antd
const Box 			= $Lazy.load(()=>import('#tp/box/box'))
const $cache 		= $Lazy.file(()=>import('#private/cache-api'))
const PatientInfoModal 		= $Lazy.state(()=>import('../../common/patient-info-modal'))
// ===================================================================== component
class Index extends React.Component{
	state = { 
		data: [],
	}
	
	componentDidMount(){
		this.getSelect()
	}
	
	// 获取下拉数据
	getSelect = () => {
		$cache.then( async f => {
			this.hostData = await f.getCache({ api:COVIDUrl+'Hospital/query',param:{page:1,page_num:10000,status:1} })
		})
	}
	
	// 加载表格数据
	fetch = () => $fn.fetch.call(this, COVIDUrl+'caseinfo/query',{COVID: true})
	
	cols = [
		{ title: '申请单条码', 		dataIndex: 'specCode', 			width:130 },
		{ title: '审核状态', 		dataIndex: 'status', 			...$fn.table.status,	render: text => $fn.getState(Status,text) },
		{ title: '受检人姓名', 		dataIndex: 'patientName', 		...$fn.table.name },
		{ title: '受检人类型', 		dataIndex: 'caseType', 			width:120,				render: text => $fn.getState(CaseType,text) },
		{ title: '受检类型', 		dataIndex: 'checkType', 		width:100,	render: text => $fn.getState(CheckType,text) },
		{ title: '性别', 			dataIndex: 'sex', 				...$fn.table.sex, 		render: text => $fn.getState(Sex,text) },
		{ title: '年龄', 			dataIndex: 'age', 				...$fn.table.age },
		{ title: '受检人电话', 		dataIndex: 'patientPhone', 		...$fn.table.phone },
		{ title: '证件类型', 		dataIndex: 'cardType', 			...$fn.table.card_type,	render: text => $fn.getState(CardType,text) },
		{ title: '证件号', 			dataIndex: 'cardNo', 			...$fn.table.idcard },
		{ title: '采集类型', 		dataIndex: 'isMultiple', 		width:100,	render: text => $fn.getState(MultipleType,text) },
		{ title: '送检单位', 		dataIndex: 'hospId', 			width:180,	render: text => $fn.getState(this.hostData,text,'hospName','uuid') },
		{ title: '送检科室', 		dataIndex: 'departmentName', 	width:180 },
		{ title: '采样时间', 		dataIndex: 'collTime',  		...$fn.table.time },
		{ title: '录入时间', 		dataIndex: 'createdAt',  			...$fn.table.time },
		{ title: '送检医生', 		dataIndex: 'doctor', 			...$fn.table.name },
		{ title: '医生电话', 		dataIndex: 'doctorPhone', 		...$fn.table.phone },
		{ title: '医院标识', 		dataIndex: 'hospRemark', 			width:150 },
		{ title: '医院说明', 		dataIndex: 'hospText', 				width:180 },
		{ title: '临床诊断', 		dataIndex: 'clinicalDiagnosis', 	width:180 },
		{ title: '备注', 			dataIndex: 'remark', 			width:180 },
		TableControls.controls.call(this,{ width: 100 })
	]
	table_controls = ({uuid}) => {
		return [
			Controls.click.call(this,'编辑',()=>this.patientInfoModal.open(uuid))
		]
	}
	
	render(){
		return (
			<>
				<Box title='资料列表' className='ex fv h' contentClassName='fv pt10 ex'>
					{ Table.call(this)}
				</Box>
				<PatientInfoModal onRef={ref => this.patientInfoModal = ref} onRefresh={ () => this.fetch() } />
			</>
			
		)
	}
}

export default Index